package io.zw.modules.xinpai.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import io.zw.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.zw.modules.xinpai.entity.CarDataEntity;
import io.zw.modules.xinpai.service.CarDataService;
import io.zw.common.utils.PageUtils;
import io.zw.common.utils.R;



/**
 * 
 *
 * @author zhuwei
 * @email 121203654@qq.com
 * @date 2018-10-10 13:15:04
 */
@RestController
@RequestMapping("xinpai/cardata")
public class CarDataController {
    @Autowired
    private CarDataService carDataService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("xinpai:cardata:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = carDataService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("xinpai:cardata:info")
    public R info(@PathVariable("id") Long id){
        CarDataEntity carData = carDataService.selectById(id);

        return R.ok().put("carData", carData);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("xinpai:cardata:save")
    public R save(@RequestBody CarDataEntity carData){
        carDataService.insert(carData);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("xinpai:cardata:update")
    public R update(@RequestBody CarDataEntity carData){
        ValidatorUtils.validateEntity(carData);
        carDataService.updateAllColumnById(carData);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("xinpai:cardata:delete")
    public R delete(@RequestBody Long[] ids){
        carDataService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 列表
     */
    @RequestMapping("/select")
    @RequiresPermissions("xinpai:cardata:list")
    public R select(@RequestParam Map<String, Object> params){
        List<CarDataEntity> list=carDataService.selectList(new EntityWrapper<CarDataEntity>().eq("imei",params.get("imei")).ge("data_time",params.get("startTime")).le("data_time",params.get("endTime")).orderBy("data_time"));
        return R.ok().put("list",list);
    }

}
